﻿using System;
using System.Linq;
using System.Web.Mvc;
using Icms.Core.Model;
using Icms.Core.Repository;
using Omu.Awesome.Mvc;

namespace Icms.WebUI.Controllers
{
    public class ClassifierIdLookupController : LookupController
    {
        private readonly IRepo<Classifier> r;

        public ClassifierIdLookupController(IRepo<Classifier> r)
        {
            this.r = r;
        }

        [HttpPost]
        public ActionResult Search(string search)
        {
            return View(@"Awesome\LookupList", 
                r.GetAll().Where(o => string.IsNullOrWhiteSpace(search) || o.Title.StartsWith(search)));
        }

        public ActionResult Get(Guid id)
        {      
            return Content((r.Get(id) ?? new Classifier()).Title);
        }
    }
}